# -*- coding:utf-8 -*-
__author__ = 'shuxin'
__date__ = '2020/8/25  12:26'

# -*- coding:utf-8 -*-
__author__ = 'shuxin'
__date__ = '2020/8/3  18:03'

import hashlib


class VirtualCardUtil:
    YISHANGLV_CODE = 'A5deW3GshGYwiy3v'

    @classmethod
    def md5(cls, s: str):
        my_md5 = hashlib.md5()  # 获取一个MD5的加密算法对象
        my_md5.update(s.encode('utf-8'))  # 得到MD5消息摘要
        my_md5_Digest = my_md5.hexdigest()  # 以16进制返回消息摘要，32位
        return my_md5_Digest

    @classmethod
    def get_digest(cls, request_data):
        md5_str = ""
        for key in request_data:
            md5_str += str(request_data[key])
        md5_str += cls.YISHANGLV_CODE
        my_md5_Digest = cls.md5(md5_str)
        return my_md5_Digest


if __name__ == '__main__':
    # 开卡申请
    # dict_str = {
    #     "customerCode": "ceshi-001",
    #     "applyCurrencyCode": "USD",
    #     "applyAmount": "10.11",
    #     "customerTransId": "trans-001",
    #     "businessOrderNo": "buss-001",
    #     "customerData": "customer-011",
    # }
    # 余额查询
    # dict_str = {
    #     "customerCode": "A027",
    # }
    # 查看使用情况
    dict_str = {
        "customerCode": "A027",
        "purchaseRequestId": "46872576",
    }
    #"messageDigest": "127e7b8c58bac940880db74a839f1caa"
    e_card = VirtualCardUtil.get_digest(dict_str)
    print(e_card)
